package ex3.render.raytrace;

import java.util.Map;
import math.*;

/**
 * Surface object, to be used by common shapes to get
 * their material representation and attributes
 *
 */
public abstract class Surface implements IInitable
{
	public Material material;
	
	/**
	 * Initialize surface with attributes parsed from XML
	 * @param attributes
	 */
	public Surface(Map <String, String> attributes) {
		material = new Material(attributes);
	}
	
	/**
	 * Generic constructor, attributes to be filled in later
	 */
    public Surface() {
        material = new Material();
    }
    
    /**
     * Load XML attributes into a Surface object constructed
     * @param attributes
     */
    public void init(Map <String, String> attributes)
    {
        material = new Material();
        material.init(attributes);
    }

	/**
	 * Computes ray's distance to surface. Returns PosInf if no intersection
	 * @param ray, ray to be examined
	 * @param flag, to determine for some shapes which face is being rendered
	 * @return, numerical positive distance
	 */
    public abstract double nearestIntersection(Ray ray, boolean face);
    
	/**
	 * Computes the surface's normal at a given intersection point
	 * 
	 * @param intersection
	 *            Point where ray intersected surface
	 * @param ray
	 *            Ray originating the intersection
	 * @return Normalized vector
	 */
    public abstract Vec normalAt(Point3D point3d, Ray ray);

}